/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dk.rofl.items;

import java.io.Serializable;
import rofl.Utils;

/**
 *
 * @author menderleit
 */
public abstract class GameItem implements Serializable {

    // Item types.
    public static final int TYPE_ARMOR = 0;
    public static final int TYPE_WEAPON = 1;
    public static final int TYPE_POTION = 2;
    // Item attributes.
    private int itemType;
    private String itemName;
    private int itemLevel;

    // Constructor
    public GameItem(int itemType, String itemName, int itemLevel) {
        this.itemType = itemType;
        this.itemName = itemName;
        this.itemLevel = itemLevel;
    }

    // Get the type of item this is.
    public int getItemType() {
        return itemType;
    }

    // Set the name of this item.
    public void setName(String name) {
        this.itemName = name;
    }

    // Get the name of this item.
    public String getName() {
        return itemName;
    }

    public int getItemLevel() {
        return itemLevel;
    }

    public static GameItem generateItem(int itemLevel) {
        return generateItem(generateItemType(), itemLevel, Equipment.generateItemQuality());
    }
    
    public static GameItem generateItem(int itemType, int itemLevel, int itemQuality) {
        GameItem gi = null;
        switch (itemType) {
            case GameItem.TYPE_ARMOR:
                gi = Armor.generateArmor(itemLevel, itemQuality);
                break;
            case GameItem.TYPE_WEAPON:
                gi = Weapon.generateWeapon(itemLevel, itemQuality);
                break;
            case GameItem.TYPE_POTION:
                gi = new HealthPotion(itemLevel);
                break;
        }
        return gi;
    }

    public static int generateItemType() {
        int itemType = GameItem.TYPE_ARMOR;

        int r = Utils.rnd().nextInt(100);
        if (r < 40) {
            itemType = GameItem.TYPE_POTION;
        }
        if (r >= 40 && r < 75) {
            itemType = GameItem.TYPE_ARMOR;
        }
        if (r >= 75 && r < 100) {
            itemType = GameItem.TYPE_WEAPON;
        }

        return itemType;
    }
}
